import { Controller, Get, Post,Param, Body } from '@nestjs/common';
import { UserService } from './user.service';
import { UserCreateDto } from './dto/user.login.dto';
import { generateId } from '../util';
@Controller('user')
export class UserController {
  constructor(private readonly UserServiceAlias: UserService) {}

  @Get('/:userId')
  async findOne(@Param('userId') id): Promise<{}> {
    return await this.UserServiceAlias.findOne(id);
  }

  @Post('/regist')
  async create(@Body() body:UserCreateDto): Promise<{}>{
    const bd = { ...body, userId: generateId() }
    return await this.UserServiceAlias.create(bd);
  }

  @Post('/login')
  async login(@Body() body:UserCreateDto): Promise<{}>{
    return await this.UserServiceAlias.login(body);
  }

  @Post('/openId')
  async getOpenID(@Body() body): Promise<{}>{
    return await this.UserServiceAlias.getOpenID(body);
  }
}
